﻿#ifndef __IRUNABLE_H__
#define __IRUNABLE_H__

#include "Thread.h"

namespace sky
{

    // 可运行对象
    struct IRunable
    {
        virtual void run() = 0;
        virtual void release() = 0;
    };


    // 线程任务类
    class ThreadRunnable: public IRunable
    {
    public:
        ThreadRunnable():m_Thread(NULL), m_bRun(true)
        {

        }

        virtual ~ThreadRunnable()
        {
            if (m_Thread)
            {
                m_Thread->clearTask();
                m_Thread = NULL;
            }

            m_bRun = false;
        }

        void setThread(Thread * pThread)
        {
            m_Thread = pThread;
        }

        virtual void notifyStop() {m_bRun = false;};
        virtual bool isRun(){return m_bRun;};
        virtual void setRun(bool bRun) {m_bRun = bRun;};
    
    protected:
        // 对应的线程
        Thread * m_Thread;

        // 是否在运行
        bool m_bRun;
    };

    
} // namespace sky



#endif